import dayjs from "dayjs"

export const formatTypeDate = (time: string, type = "YYYY", format = "YYYY-MM-DD HH:MM:ss") => {
  let formatDate
  switch (type) {
    case "YYYY":
      formatDate = dayjs(time).year()
      break
    case "MM":
      formatDate = dayjs(time).month() + 1
      break
    case "DD":
      formatDate = dayjs(time).date()
      break
    case "HH":
      formatDate = dayjs(time).hour()
      break
    case "YYYY-MM-DD":
      formatDate = dayjs(time).year() + "-" + dayjs(time).month() + 1 + "-" + dayjs(time).date()
      break
    case "YYYY-MM":
      formatDate = dayjs(time).year() + "-" + dayjs(time).month() + 1
      break
    case "MM-DD":
      formatDate = dayjs(time).month() + 1 + "-" + dayjs(time).date()
      break
    default:
      formatDate = dayjs(time).format(format)
  }
  return formatDate
}

export const isValidKey = (key: string | number | symbol, object: object): key is keyof typeof object => {
  return key in object
}


